import React from 'react';

class App extends React.Component {

    constructor(props) {
        super(props);

        this.state = {
            count: 0
        };

        //指定this指向
        this.Add = this.Add.bind(this);

    }

    Add() {
        this.setState({
            count: this.state.count + 1
        });
    }

    // @babel/plugin-proposal-class-properties
    AddTwo = () => {
        this.setState({
            count: this.state.count + 1
        });
    }

    // @babel/plugin-proposal-class-properties
    AddThree = (number) => {
        this.setState({
            count: this.state.count + number
        });
    }

    render() {
        return (
            <div>
                {/* 匿名箭头函数 */}
                <button onClick={() => this.setState({ count: this.state.count + 1 })}>{this.state.count}</button>

                {/* // this.Add = this.Add.bind(this);  */}
                <button onClick={this.Add}>{this.state.count}</button>

                {/* //箭头函数 */}
                <button onClick={this.AddTwo}>{this.state.count}</button>

                {/* //匿名箭头函数 */}
                <button onClick={() => this.AddThree(2)}>{this.state.count}</button>
            </div>
        );
    }
}
export default App;